<template>
  <div class="login">
    <div class="loginYe">
      <h3>登录</h3>
      <el-input placeholder="请输入用户名" v-model="loginData.username"></el-input>
      <el-input
        placeholder="请输入密码"
        v-model="loginData.password"
        show-password
      ></el-input>
      <el-button type="primary" @click="login()">登录</el-button>
      <el-button @click="$router.push('/register')">注册</el-button>
    </div>
  </div>
</template>

<script>
import { login, register } from "../api/index";
export default {
  name: "login",
  data() {
    return {
      loginData: {
        username: "admin",
        password: "admin",
      }
    };
  },
  created() {},
  methods: {
    login() {
      login(this.loginData).then((res) => {
        console.log(res);
        if(res.data.status == 0){
          localStorage.setItem("data",JSON.stringify(res.data))
          this.$message.success("登陆成功")
          this.$router.push("/home")
        }
      });
    }
  },
};
</script>

<style scoped lang="scss">
.login{
  width: 100%;
  height: 100vh;
  display: flex;
  .loginYe{
    width: 600px;
    height: 300px;
    margin: auto;
    h2{
      text-align: center;
    }
  }
}
</style>
